#ifndef PROJECTLOADER_HOOKS_H
#define PROJECTLOADER_HOOKS_H

class TiXmlElement;
class M_Code_Project;

namespace ProjectLoaderHooks {
  class HookFunctorBase {
    public:
      virtual ~HookFunctorBase() {}
      virtual void Call( M_Code_Project*, TiXmlElement*, bool ) const = 0;
  };
  template<class T> class HookFunctor : public HookFunctorBase {
    public:
      typedef void ( T::*Func )( M_Code_Project*, TiXmlElement*, bool );
      HookFunctor( T* obj, Func func ) : m_pObj( obj ), m_pFunc( func ) { ; }
      virtual void Call( M_Code_Project* project, TiXmlElement* elem, bool isLoading ) const {
        if( m_pObj && m_pFunc ) {
          ( m_pObj->*m_pFunc )( project, elem, isLoading );
        }
      }
    protected:
      T* m_pObj;
      Func m_pFunc;
  };
  extern int RegisterHook( HookFunctorBase* functor );
  extern HookFunctorBase* UnregisterHook( int id, bool deleteHook = true );
  extern bool HasRegisteredHooks();
  extern void CallHooks( M_Code_Project* project, TiXmlElement* elem, bool isLoading );
}

#endif
